﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LogisticsCrawler.Core;
using System.Text;
using System.IO;

namespace LogisticsCrawler.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        public static string _where { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _where = "MainType='" + Request["where"] + "'";
                GetDataSource(_where);
                OutputExcel();
            }
        }

        /// <summary>
        /// 绑定
        /// </summary>
        private void GetDataSource(string where)
        {
            IList<CrawlerCompany> list
                = ManagerFactory.ManagerCrawlerCompany.SelectByWhere(where);
            this.gdTable.DataSource = list;
            this.gdTable.DataBind();
        }


        /// <summary>
        /// 输出EXCEL
        /// </summary>
        private void OutputExcel()
        {
            Response.ClearContent();
            Response.Charset = "utf-8";
            Response.Buffer = true;
            Response.ContentEncoding = Encoding.UTF8;
            //.GetEncoding("GB2312");
            //Encoding.UTF7;
            Response.AppendHeader("Content-Disposition", "attachment;filename=enterprise_"
                +DateTime.Now.ToString("yyyyMMddHHmm")+".xls");
            //Response.AddHeader("content-disposition", "attachment; filename=HpUploadRecord.xls");
            Response.ContentType = "application/ms-excel";
            gdTable.Page.EnableViewState = false;
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            StringWriter sw = new StringWriter(myCItrad);
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gdTable.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control); 
        }
    }
}
